package com.wolfking.jeesite.freemarker.tag;

import com.wolfking.jeesite.freemarker.FreemarkerTag;
import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateDirectiveModel;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;

import java.io.IOException;
import java.util.Map;
import java.util.Set;

/**
 * freemarker的treeview的tag
 * <p>
 *
 * @author wolfking@赵伟伟
 * @mail zww199009@163.com
 * @创作日期 2017年4月28日下午3:50:30
 * @版权 归wolfking所有
 */
@FreemarkerTag("treeView")
@SuppressWarnings({"rawtypes", "unchecked"})
public class TreeViewTag implements TemplateDirectiveModel {

    @Override
    public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
            throws TemplateException, IOException {
        if (params != null) {
            Set<Map.Entry> set = params.entrySet();
            for (Map.Entry entry : set)
                env.getCurrentNamespace().put("tree_" + entry.getKey(), entry.getValue());
            body.render(env.getOut());
        }
    }
}
